import {postStream} from '@/api/Http'

export interface TranslationRequest {
  content: string
  sourceLanguage: string
  targetLanguage: string
}

export class TranslationApi {
  static async translate(data: TranslationRequest): Promise<ReadableStreamDefaultReader<Uint8Array>> {
    const response = await postStream('/utility/translation/translate', {
      content: data.content,
      targetLanguage: data.targetLanguage,
      sourceLanguage: data.sourceLanguage
    })

    if (!response.ok) {
      throw new Error(`Translation failed: ${response.statusText}`)
    }

    if (!response.body) {
      throw new Error('No response body')
    }

    return response.body.getReader()
  }
}
